import { copyFileSync, existsSync, mkdirSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

/**
 * 构建后处理脚本
 * 复制类型定义文件到dist目录
 * @author Ning,Li
 */

const rootDir = resolve(__dirname, '..');
const srcDir = resolve(rootDir, 'src');
const distDir = resolve(rootDir, 'dist');

// 确保dist目录存在
if (!existsSync(distDir)) {
  mkdirSync(distDir, { recursive: true });
}

// 复制类型定义文件
const typesFile = resolve(srcDir, 'index.d.ts');
const distTypesFile = resolve(distDir, 'index.d.ts');

if (existsSync(typesFile)) {
  copyFileSync(typesFile, distTypesFile);
  console.log('✓ 类型定义文件已复制到 dist/index.d.ts');
} else {
  console.warn('⚠ 未找到类型定义文件 src/index.d.ts');
}

console.log('✓ 构建后处理完成'); 